'''
Author: Adam Stylinski
This body of work is largely based upon the tsp solver javascript code found here:

 http://code.google.com/p/google-maps-tsp-solver

The intent of this library is to aid in allowing for a server-side service to access
perform the tsp operations preventing any operation from happening client-side.  This
will not only offload the work from whatever embedded device is accessing the webapp,
but will also prevent the user from requiring a browser and/or javascript interpreter.

Users of this library should take extra care to only allow execution of this code if
the user is authenticated, or else the 25,000 API calls per day limit is very very
easy to hit.

'''

import types
from googlemaps import GoogleMaps

# For now it seems we don't actually need a key but we may want one later
GMAPS_API_KEY = open('gmaps-api-key.txt').readline().strip()

class TspSolver:
    ''' A class for solving the TSP akin to the one done by Geir K. Engdahl and James Tolley '''
    def __init__(self, addrslistin=list()):
        ''' addrslistin is a list of waypoints in any given order '''
        self.addrs = addrslistin
        ''' This is the google maps geocoder and other various functions '''
        self.gmap = GoogleMaps(GMAPS_API_KEY)
        self.maxTspSize = 100 # limit size of the problem
        self.maxTspBF = 0 # Max size for brute force
        self.maxTspDynamic = 15 # Max Size for brute force
        self.maxSize = 10 # Max number of waypoints in one request
        self.maxTripSentry = 2000000000 # 63 years maximum trip time
        self.avoidHighways = false
        self.distIdx = None
        self.costForwards = list()
        self.costBackwards = list()


    def addWaypoints(self, waypoints=list()):
        ''' adds a list of more waypoints or a single waypoint '''
        if isinstance(waypoints, types.ListType):
            self.addrs.extend(waypoints)
        elif isinstance(waypoints, types.StringTypes):
            self.addrs.append(waypoints)
        else:
            print('argument to addWaypoints is invalid')
            return


    def __cost(self, a, b)
    ''' Computes the cost of moving between point a and b '''
    cost
